package main

import (
	"crypto/md5"
	"crypto/sha512"
	"encoding/hex"
	"fmt"
	"io"
	"strings"

	"github.com/anaskhan96/go-password-encoder"
)

func genMd5(code string) string {
	m := md5.New()
	_, _ = io.WriteString(m, code)
	return hex.EncodeToString(m.Sum(nil))
}

func main() {
	//salt, encodedPwd := password.Encode("generic password", nil)
	//fmt.Println("salt", salt)
	//fmt.Println("encodedPwd", encodedPwd)
	//check := password.Verify("generic password", salt, encodedPwd, nil)
	//fmt.Println(check) // true

	// Using custom options
	options := &password.Options{SaltLen: 16, Iterations: 100, KeyLen: 32, HashFunction: sha512.New}
	salt, encodedPwd := password.Encode("generic password", options)
	passwd := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)
	fmt.Println("len(passwd)", len(passwd))
	fmt.Println("passwd", passwd)

	passwdInfo := strings.Split(passwd, "$")
	check := password.Verify("generic password", passwdInfo[2], passwdInfo[3], options)
	fmt.Println(check) // true
}
